package cn.edu.tsinghua.cs.jwh;

public class DistanceOfLatLng {
	private static double EARTH_RADIUS = 6378.137;  
	private static double TIMES = 1000000;
	public static double getDistance(double lat_a, double lng_a, double lat_b, double lng_b) {
        double radLat1 = (lat_a / TIMES * Math.PI / 180.0);
        double radLat2 = (lat_b / TIMES * Math.PI / 180.0);
        double a = radLat1 - radLat2;
        double b = (lng_a / TIMES - lng_b / TIMES) * Math.PI / 180.0;
        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
              + Math.cos(radLat1) * Math.cos(radLat2)
              * Math.pow(Math.sin(b / 2), 2)));
        s = s * EARTH_RADIUS;
        return s;
    }
}
